#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

int main()
{
    int n;cin>>n;
    priority_queue<LL,vector<LL>,greater<>>q;
    while(n--)
    {
        LL x;
        cin>>x;
        q.push(x);
    }
    LL ret=0;
    while(q.size()>1)
    {
        LL a=q.top();q.pop();
        LL b=q.top();q.pop();
        q.push(a+b);
        ret+=a+b;
    }
    cout<<ret<<endl; 
    return 0;
}